package action;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;

import service.service_admin.Service_Admin;
import service.service_public.Service_Public;
import service.service_search.Service_Search;
import tools.InterfaceDepthPlaList;
import tools.PageBeanPlus;
import entitybean.l_sequence.EntityBeanL_Sequence;
import entitybean.oc_depthlist_pla.EntityBeanOc_Depthlist_Pla;
import form.DepthPlaForm;

public class Action_Oc_Depthlist_Pla extends DispatchAction{
	private Service_Admin service_admin;
    private Service_Public service_public;
 	private Service_Search service_search;
	public Service_Admin getService_admin() {
		return service_admin;
	}

	public void setService_admin(Service_Admin service_admin) {
		this.service_admin = service_admin;
	}

	public Service_Public getService_public() {
		return service_public;
	}

	public void setService_public(Service_Public service_public) {
		this.service_public = service_public;
	}

	public Service_Search getService_search() {
		return service_search;
	}

	public void setService_search(Service_Search service_search) {
		this.service_search = service_search;
	}

	public ActionForward admin_init_oc_depthlist_pla(ActionMapping mapping,
			ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		DepthPlaForm depthIceForm = (DepthPlaForm) form;
		depthIceForm.setCurrentpage("1");
		depthIceForm.setDepth("");
		depthIceForm.setOver_time("");
		depthIceForm.setStart_time("");
		String sql = "select id,depth  from oc_depthlist_pla where del='OFF' ORDER BY id DESC";
		PageBeanPlus pagebeanplus = new PageBeanPlus("oracle", "sql", sql,
				Integer.valueOf(depthIceForm.getRowcountperpage()), Integer
						.valueOf(depthIceForm.getCurrentpage()),
				"loadrichtext()");
		InterfaceDepthPlaList interfaceforresultsettolist = new InterfaceDepthPlaList();
		List<EntityBeanOc_Depthlist_Pla> list = interfaceforresultsettolist.ViewOc_News(pagebeanplus.getFormatqueryresultset());

		request.setAttribute("pagebeanplus", pagebeanplus);
		request.setAttribute("list", list);
		request.setAttribute("newslistform", depthIceForm);
		System.out.println("list.size()" + list.size());
		return mapping.findForward("success");
	}

	public ActionForward admin_load_oc_depthlist_pla(ActionMapping mapping,
			ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		return null;
	}

	public ActionForward admin_add_depthlist_pla(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		return mapping.findForward("success");
	}

	public ActionForward admin_insert_depthlist_pla(ActionMapping mapping,
			ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		DepthPlaForm actionForm = (DepthPlaForm) form;
		String depth=actionForm.getDepth();
		EntityBeanOc_Depthlist_Pla link=new EntityBeanOc_Depthlist_Pla();
        link.setDepth(Integer.valueOf(depth));
		link.setDel("OFF");
		Integer i=0;
		EntityBeanL_Sequence entity=new EntityBeanL_Sequence();
		entity=this.service_public.Find_L_Sequence_By_seq_Name("SEQ_OC_DEPTH_PLA");
		i=entity.getSeq_Value()+1;
		entity.setSeq_Value(i);
		link.setId(i);
		this.service_public.Update_L_Sequence(entity);
		this.service_search.Insert_Oc_DepthPla_Pla(link);
		System.out.println("初始化新闻模块");
		// 封装新闻查询的数据及表单
		DepthPlaForm goodForm = (DepthPlaForm) form;
		goodForm.setCurrentpage("1");
		goodForm.setDepth("");
		goodForm.setOver_time("");
		goodForm.setStart_time("");
		String sql = "select id,depth  from oc_depthlist_pla where del='OFF' ORDER BY id DESC";
		PageBeanPlus pagebeanplus = new PageBeanPlus("oracle", "sql", sql,
				Integer.valueOf(goodForm.getRowcountperpage()), Integer
						.valueOf(goodForm.getCurrentpage()),
				"loadrichtext()");
		InterfaceDepthPlaList interfaceforresultsettolist = new InterfaceDepthPlaList();
		List<EntityBeanOc_Depthlist_Pla> list = interfaceforresultsettolist.ViewOc_News(pagebeanplus.getFormatqueryresultset());


		request.setAttribute("pagebeanplus", pagebeanplus);// 设置传递到页面的数据
		request.setAttribute("list", list);
		request.setAttribute("newslistform", goodForm);
		return mapping.findForward("success");
	}

	public ActionForward admin_delete_depthlist_pla(ActionMapping mapping,
			ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		DepthPlaForm actionForm = (DepthPlaForm) form;
		String id = actionForm.getId();
		id = this.cut_tail(id);
		this.service_search.Delete_Oc_DepthPla_Pla(id);

		String sql = "select id,depth  from oc_depthlist_pla where del='OFF' ORDER BY id DESC";
		PageBeanPlus pagebeanplus = new PageBeanPlus("oracle", "sql", sql,
				Integer.valueOf(actionForm.getRowcountperpage()), Integer.valueOf(actionForm
						.getCurrentpage()), "loadrichtext()");
		InterfaceDepthPlaList interfaceforresultsettolist = new InterfaceDepthPlaList();
		List<EntityBeanOc_Depthlist_Pla> list = interfaceforresultsettolist.ViewOc_News(pagebeanplus.getFormatqueryresultset());

		request.setAttribute("pagebeanplus", pagebeanplus);// 设置传递到页面的数据
		request.setAttribute("list", list);
		request.setAttribute("newslistform", actionForm);
		System.out.println("list.size()" + list.size());
		return mapping.findForward("success");
	}
	public ActionForward admin_init_update_depthlist_pla(ActionMapping mapping,
			ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		DepthPlaForm actionForm = (DepthPlaForm) form;
		String id=actionForm.getId();
		EntityBeanOc_Depthlist_Pla link=this.service_search.Find_EntityBeanOc_Depthlist_Pla(Integer.valueOf(id));
		request.setAttribute("PlaceView" , link); 
		return mapping.findForward("success");
	}
	public ActionForward admin_update_depthlist_pla(ActionMapping mapping,
			ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		DepthPlaForm actionForm = (DepthPlaForm) form;
		String depth=actionForm.getDepth();
		String id=actionForm.getId();
		EntityBeanOc_Depthlist_Pla link=new EntityBeanOc_Depthlist_Pla();
		link.setDepth(Integer.valueOf(depth));
		link.setDel("OFF");
		link.setId(Integer.valueOf(id));
		this.service_search.Update_Oc_DepthPla_Pla(link);
		DepthPlaForm goodForm = (DepthPlaForm) form;
		goodForm.setCurrentpage("1");
		goodForm.setDepth("");
		goodForm.setOver_time("");
		goodForm.setStart_time("");
		String sql = "select id,depth  from oc_depthlist_pla where del='OFF' ORDER BY id DESC";
		PageBeanPlus pagebeanplus = new PageBeanPlus("oracle", "sql", sql,
				Integer.valueOf(goodForm.getRowcountperpage()), Integer.valueOf(goodForm
						.getCurrentpage()), "loadrichtext()");
		InterfaceDepthPlaList interfaceforresultsettolist = new InterfaceDepthPlaList();
		List<EntityBeanOc_Depthlist_Pla> list = interfaceforresultsettolist.ViewOc_News(pagebeanplus.getFormatqueryresultset());

		request.setAttribute("pagebeanplus", pagebeanplus);// 设置传递到页面的数据
		request.setAttribute("list", list);
		request.setAttribute("newslistform", goodForm);
	    return mapping.findForward("success");
	}

	public ActionForward admin_search_depthlist_pla(ActionMapping mapping,
			ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		DepthPlaForm actionForm = (DepthPlaForm) form;
		String sql="select id,depth  from oc_depthlist_pla where del='OFF' ORDER BY id DESC";
		PageBeanPlus pagebeanplus=new PageBeanPlus("oracle", "sql",sql,
				Integer.valueOf(actionForm.getRowcountperpage()), Integer.valueOf(actionForm.getCurrentpage()),"loadrichtext()");
		InterfaceDepthPlaList interfaceforresultsettolist = new InterfaceDepthPlaList();
		List<EntityBeanOc_Depthlist_Pla> list = interfaceforresultsettolist.ViewOc_News(pagebeanplus.getFormatqueryresultset());
		
		request.setAttribute("pagebeanplus", pagebeanplus);//设置传递到页面的数据
		request.setAttribute("list", list);
		request.setAttribute("newslistform", actionForm);
		System.out.println("list.size()"+list.size());
		return mapping.findForward("success");
	}

	private String cut_tail(String str) {
		String cut = str;
		if (str.endsWith(",")) {
			cut = cut.substring(0, cut.length() - 1);
		}
		return cut;
	}
}
